﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using OpenComposite.EII.Repository;
using System.Reflection;
using Aga.Controls.Tree.NodeControls;
using Aga.Controls.Tree;
using OpenComposite.Repository.Properties;
using OpenComposite.EII.Designer.Workflow;
using System.Collections.ObjectModel;
using WeifenLuo.WinFormsUI.Docking;

namespace OpenComposite.EII.Simulation
{
	public partial class FormBusinessObjectDataInput : DockContent
	{
		public FormBusinessObjectDataInput()
		{
			InitializeComponent();
			init();
			this.DialogResult = DialogResult.None;
		}

		public FormBusinessObjectDataInput(string capability, object obj)
			: this()
		{
			_text = capability;
			_orchestration = obj;
		}

		#region Public Member
		#region Properties
		public List<BusinessObject> InputBusinessObjects
		{
			get { return _input; }
			set { _input = value; }
		}
		public List<BusinessObject> AdditionalBusinessObjects
		{
			get { return _additional; }
			set { _additional = value; }
		}
		public BusinessObject OutputBusinessObject
		{
			get { return _output; }
			set
			{
				_output = value;
				load();
			}
		}
		public Assembly CompiledAssembly
		{
			get { return _compiledAssembly; }
			set { _compiledAssembly = value; }
		}
		public WorkflowController Controller
		{
			get { return _wfController; }
			set { _wfController = value; }
		}
		#endregion

		#region Methods
		#endregion
		#endregion

		#region Private Member
		#region Fields
		private List<BusinessObject> _input = null;
		private List<BusinessObject> _additional = null;
		private BusinessObject _output = null;
		private Assembly _compiledAssembly = null;
		private WorkflowController _wfController = null;
		private object _orchestration = null;
		private string _text = string.Empty;
		#endregion

		#region Methods
		#region init / load
		private void init()
		{
		}

		private void load()
		{
			//generateTree();
			//readObject();
		}
		#endregion

		#endregion

		#region Event Handlers
		private void tsbtnOK_Click(object sender, EventArgs e)
		{
			Type orchType = _orchestration.GetType();
			SimulationVariable rootVar = outputView.RootNode as SimulationVariable;
			PropertyInfo outProp = orchType.GetProperty(rootVar.VarName);

			outProp.SetValue(_orchestration, outputView.CreateInputObject(rootVar), null);
			this.Tag = _orchestration;
			this.DialogResult = DialogResult.OK;
			this.Close();
		}

		#endregion
		#endregion
	}
}
